package edu.washington.cs.sounddetector.server.api.method;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;

import edu.washington.cs.sounddetector.server.api.Method;
import edu.washington.cs.sounddetector.server.api.object.PeakEvent;
import edu.washington.cs.sounddetector.server.api.object.SoundFormat;

public class Classify implements Method
{
    private String detectorId;
    private byte[] sound;
    private SoundFormat soundFormat;
    private List<PeakEvent> peakEvents;

    public Classify()
    {
    }

    public Classify(String detectorId, byte[] sound, SoundFormat soundFormat,
            List<PeakEvent> peakEvents)
    {
        Validate.notBlank(detectorId);
        Validate.notNull(sound);
        Validate.isTrue(sound.length != 0);
        Validate.notNull(soundFormat);
        Validate.notEmpty(peakEvents);
        Validate.noNullElements(peakEvents);

        this.detectorId = detectorId;
        this.sound = sound;
        this.soundFormat = soundFormat;
        this.peakEvents = peakEvents;
    }

    /**
     * @param detectorId
     *            the detectorId to set
     */
    public void setDetectorId(String detectorId)
    {
        this.detectorId = detectorId;
    }

    /**
     * @param sound
     *            the sound to set
     */
    public void setSound(byte[] sound)
    {
        this.sound = sound;
    }

    /**
     * @param soundFormat
     *            the soundFormat to set
     */
    public void setSoundFormat(SoundFormat soundFormat)
    {
        this.soundFormat = soundFormat;
    }

    /**
     * @param peakEvents
     *            the peakEvents to set
     */
    public void setPeakEvents(List<PeakEvent> peakEvents)
    {
        this.peakEvents = peakEvents;
    }

    /**
     * @return the soundFormat
     */
    public SoundFormat getSoundFormat()
    {
        return soundFormat;
    }

    /**
     * @return the detectorId
     */
    public String getDetectorId()
    {
        return detectorId;
    }

    /**
     * @return the sound
     */
    public byte[] getSound()
    {
        return sound;
    }

    /**
     * @return a new list containing the peak events
     */
    public List<PeakEvent> getPeakEvents()
    {
        return new ArrayList<PeakEvent>(peakEvents);
    }

    @Override
    public String toString()
    {
        return new ToStringBuilder(this).append("detectorId", detectorId).append("sound", sound)
                .append("soundFormat", soundFormat).append("peakEvents", peakEvents).toString();
    }
}
